/*
 * ChessTable.h
 *
 *  Created on: 18 Jan 2011
 *      Author: sinan
 */

#ifndef CHESSTABLE_H_
#define CHESSTABLE_H_

#include <vector>
#include "ChessMan.h"
#include "ChessMen/Bishop.h"
#include "ChessMen/King.h"
#include "ChessMen/Knight.h"
#include "ChessMen/Pawn.h"
#include "ChessMen/Queen.h"
#include "ChessMen/Rook.h"
#include "Game.h"
#include "ScreenOperations.h"
#include "SoundSource.h"

using namespace std;

typedef struct _movement
{
	ChessTableCoordinate fromCoord;
	vector<ChessTableCoordinate> toCoord;
} Movement;

typedef struct _matrix {
public:
	ChessMan data[8][8];
	bool isChanged;
} ChessTableMtrx;

class ChessTable {
public:

	static ChessMan ChessTableMatrix[8][8];
	static ChessMan UndoMatrix[8][8];
	static vector<ChessMan> ChessMenDeadWhite;
	static vector<ChessMan> ChessMenDeadBlack;
	static vector<VisitableCoordinate> MovementList;
	static vector<ChessTableCoordinate> EnemyChessMenCoordinateList;
	static ChessTableCoordinate selectedCoordinate;
	static vector<VisitableCoordinate> selectedCoordinateMovementList;
	static ChessMan LastEatenWhiteChessMan;
	static ChessMan LastEatenBlackChessMan;

	ChessTable();
	~ChessTable();
	void InitializeChessTableMatrixWithNullChessMen();
	void FillChessTableMatrixForBeginning();
	void GetMovementList(ChessTableCoordinate coord, ChessMan matrix[8][8]);
	void RefineMovementList(ChessTableCoordinate coord, ChessMan matrix[8][8]);
	void GetAllEnemyChessMen(ChessManColor cmColor, ChessMan matrix[8][8]);
	bool IsKingInDanger(ChessManColor cmColor, ChessMan matrix[8][8]);
	ChessTableCoordinate GetKingChessManCoordinate(ChessManColor cmColor,
			ChessMan matrix[8][8]);
	ChessTableMtrx MakeMovement(ChessTableCoordinate oldCoord,
			ChessTableCoordinate newCoord, ChessMan matrix[8][8],
			bool isMovementReal);
	void EqualTwoArrays(ChessMan arrayOriginal[8][8],
			ChessMan arrayToEqual[8][8]);
	ChessManColor GetReverseColor(ChessManColor cmColor);
	void CheckPawnForEndLine(ChessMan matrix[8][8]);
	vector<ChessTableCoordinate> GetAllSelfChessMan(
			ChessMan chessTableMatrix[8][8], ChessManColor cmColor);
	vector<Movement> FindAllMovements(
			ChessMan chessTableMatrix[8][8], ChessManColor cmColor);
	bool IsCheckMateOrCheck(ChessMan matrix[8][8]);
	void CheckForBeatenChessMan();

};

#endif /* CHESSTABLE_H_ */
